{% extends 'layout/basic.html' %}
{% load static %}
{% block title %}
    用户登录
{% endblock %}
{% block css %}
    <link rel="stylesheet" href="{% static 'css/account.css' %}">
{% endblock %}
{% block content %}
    <div class="container">
        <div class="panel panel-default account">
            <div class="panel-heading title">用户登录</div>
            <div class="panel-body " style="padding-left: 30px; padding-right: 30px">
                <form method="post" novalidate >
                    {% csrf_token %}
                    {% for field in form %}
                        {% if field.name == 'code' %}
                            <div class="form-group clearfix">
                                <div><label for={{ field.id_for_label }}>{{ field.label }}</label></div>
                                <div class="col-md-6" style="position: relative;padding-left: 0;">
                                    {{ field }}
                                    <span class="errmsg"
                                          style="color: red;position: absolute;">{{ field.errors.0 }}</span>
                                </div>
                                <div class="col-md-6">
                                    <img src="/img/code/" alt="点击刷新验证码" id="code_img">
                                </div>
                            </div>

                        {% else %}
                            <div class="form-group" style="position: relative">
                                <label for={{ field.id_for_label }}>{{ field.label }}</label>
                                {{ field }}
                                <span class="errmsg" style="color: red;position: absolute;">{{ field.errors.0 }}</span>
                            </div>
                        {% endif %}

                    {% endfor %}
                    <div class="form-group">
                            <input type="submit" value="登录" class="btn btn-primary btn-lg" id="loginbtn" >
                            <div style="float: right">
                                <a href="{% url 'login_sms' %}">使用短信验证登录</a>
                            </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
{% endblock %}
{% block js %}
    <script>
        $(function () {
            imgCode();
        })
        function imgCode() {
            $('#code_img').click(function () {
                console.log(123)
               //this.setAttribute('src','/img/code/'+'?tm='+Math.random());
                this.src = '/img/code/'+'?tm='+Math.random()
            })
        }
    </script>
{% endblock %}